package cn.pxy.ysframework.web.Controller;

import cn.pxy.ysframework.utils.Message;
import cn.pxy.ysframework.web.Entity.Category;
import cn.pxy.ysframework.web.Service.ICategoryService;
import com.alibaba.fastjson.JSON;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping(value = "/Category")
@Api(description = "分类控制器--完成")
public class CategoryController {
    @Autowired
    private ICategoryService categoryService;

    /**
     * 获取所有分类
     * @return
     */
    @PostMapping(value = "/FindAllCategory")
    @ApiOperation(value = "获得所有分类--完成")
    public Message FindAllCategory(){
        return new Message(JSON.toJSONString(categoryService.findAllCategory()));
    }

    /**
     * 分页获取所有分类
     * @return
     */
    @PostMapping(value = "/FindAllCategoryWithPager")
    @ApiOperation(value = "分页获取所有分类--完成")
    public Message FindAllCategoryWithPager(){
        return new Message(JSON.toJSONString(categoryService.findAllCategoryWithPager(1,2)));
    }

    /**
     * 添加一个分类 (未实现)
     * @return
     */
    @PostMapping(value = "/AddCategory")
    public Message AddCategory(@RequestBody Category category){
        return null;
    }
}
